package Filters;

import FilesManagers.CantOpenFileException;

public class FullFilter extends Filter{
	
	private HtmlCleaner miHtmlCleaner;
	private StopWordsCleaner limpiadorStopWords;
	private Stemming stemming;
	private CharacterUnifier unificadorCaracteres;
	private boolean ultimaLinea;
	private boolean filtroNulo;
	public FullFilter (String bibliotecaStopWords, String bibliotecaStemming,String bibliotecaBadChars) throws CantOpenFileException{
		miHtmlCleaner = new HtmlCleaner();
		limpiadorStopWords = new StopWordsCleaner(bibliotecaStopWords);
		stemming = new Stemming(bibliotecaStemming);
		unificadorCaracteres = new CharacterUnifier(bibliotecaBadChars);
		ultimaLinea = false;
		filtroNulo=false;
	}
	public FullFilter() throws CantOpenFileException{
		//filtroNulo=true;
		//miHtmlCleaner = new HtmlCleaner();
		//ultimaLinea = false;
		this("./conf/stopwords.conf","./conf/stemming.conf","./conf/badcharacters.txt");
		
	}
	
	
	
	@Override
	public String procesarLinea(String linea) {
		 
		linea = miHtmlCleaner.procesarLinea(linea);
		//if(filtroNulo)return linea;
		if(!linea.equals(""))linea = unificadorCaracteres.procesarLinea(linea);
		limpiadorStopWords.setUltimaLinea(ultimaLinea);
		if((!linea.equals(""))||(this.ultimaLinea))linea = limpiadorStopWords.procesarLinea(linea);
		if(!linea.equals(""))linea = stemming.procesarLinea(linea);
		//System.out.println("De ullfiulter sale: "+linea.trim());
		return linea.trim();
	}
	
	public String procesarSearch(String linea) {
		//if(filtroNulo)return linea;
		if(!linea.equals(""))linea = unificadorCaracteres.procesarLinea(linea);
		limpiadorStopWords.setUltimaLinea(true);
		linea = limpiadorStopWords.procesarLinea(linea);
		if(!linea.equals(""))linea = stemming.procesarLinea(linea);
		return linea.trim();
	}
	public void setUltimaLinea(boolean ultimaLinea) {
		this.ultimaLinea = ultimaLinea;
	}
	public boolean getUltimaLinea() {
		return this.ultimaLinea;
	}

}
